﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFSoft.UBF.Business;

namespace MF_HSD_BEPlug
{
    public partial class VoucherUpdated : UFSoft.UBF.Eventing.IEventSubscriber
    {
        void UFSoft.UBF.Eventing.IEventSubscriber.Notify(object[] args)
        {
            this.Do_Notify(args);
        }

        private void Do_Notify(object[] args)
        {
            #region 从事件参数中取得当前业务实体													 

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent))
                return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;
            if (key == null)
                return;
            UFIDA.U9.GL.Voucher.Voucher holder = key.GetEntity() as UFIDA.U9.GL.Voucher.Voucher;
            if (holder == null)
                return;
            //凭证弃审校验 存在接收方凭证不为空，不允许弃审
            if((holder.OriginalData.VoucherStatus == UFIDA.U9.GL.Voucher.VoucherStatus.Approved || holder.OriginalData.VoucherStatus == UFIDA.U9.GL.Voucher.VoucherStatus.InProcessing) && (holder.VoucherStatus == UFIDA.U9.GL.Voucher.VoucherStatus.Open|| holder.VoucherStatus == UFIDA.U9.GL.Voucher.VoucherStatus.Approving))
            {
                if(!string.IsNullOrEmpty(holder.DescFlexField.PrivateDescSeg2))
                {
                    throw new Exception("存在接收方凭证不为空，不允许弃审!");
                }
            }
            #endregion

        }
    }
}
